#include "initTcp.h"

int initTcp(int *sockfd, const char *ip, char *port)
{
    *sockfd = socket(AF_INET,SOCK_STREAM,0);
    ERROR_CHECK(*sockfd, -1, "socket create failed");

    struct sockaddr_in server_addr;
    memset(&server_addr,0,sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(atoi(port));
    server_addr.sin_addr.s_addr = inet_addr(ip);

    int connectRet = connect(*sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr));
    ERROR_CHECK(connectRet, -1, "connect failed");

    return 0;
}